﻿// CProcessManagerDialog.cpp: 实现文件
//

#include "pch.h"
#include "HappyManager.h"
#include "CProcessManagerDialog.h"
#include "afxdialogex.h"


// CProcessManagerDialog 对话框

IMPLEMENT_DYNAMIC(CProcessManagerDialog, CDialogEx)

CProcessManagerDialog::CProcessManagerDialog(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_PROCESS_MANAGER_DIALOG, pParent)
{

}

CProcessManagerDialog::~CProcessManagerDialog()
{
}

void CProcessManagerDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_PROCESS_LIST, m_ProcessListCtrl);
}


BEGIN_MESSAGE_MAP(CProcessManagerDialog, CDialogEx)
END_MESSAGE_MAP()


// CProcessManagerDialog 消息处理程序


BOOL CProcessManagerDialog::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	this->initDialog();		//调用初始化控件函数
	
	SeEnumProcessInfo();	//枚举当前所有进程信息

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}

void CProcessManagerDialog::initDialog()
{
	//初始化列表控件
	m_ProcessListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT/* | LVS_EX_GRIDLINES*/);
	m_ProcessListCtrl.InsertColumn(0, _T("镜像名称"), LVCFMT_LEFT, 130);
	m_ProcessListCtrl.InsertColumn(1, _T("进程ID"), LVCFMT_LEFT, 65);
	m_ProcessListCtrl.InsertColumn(2, _T("父进程ID"), LVCFMT_LEFT, 65);
	m_ProcessListCtrl.InsertColumn(3, _T("镜像路径"), LVCFMT_LEFT, 290);
	m_ProcessListCtrl.InsertColumn(4, _T("应用层访问"), LVCFMT_CENTER, 75);
	m_ProcessListCtrl.InsertColumn(5, _T("文件厂商"), LVCFMT_LEFT, 100);
	m_ProcessListCtrl.InsertColumn(6, _T("文件描述"), LVCFMT_LEFT, 210);
	m_ProcessListCtrl.InsertColumn(7, _T("启动时间"), LVCFMT_LEFT, 200);
	m_ProcessListCtrl.InsertColumn(8, _T("进程位数"), LVCFMT_LEFT, 200);
}


void CProcessManagerDialog::SeEnumProcessInfo()
{
	m_Ring3ProcessList.clear();

	// 用CreateToolhelp32Snapshot的方法获取应用层的进程
	SeRing3EnumProcessInfo(m_Ring3ProcessList);

	//遍历Vector数据结构
	for (vector <PROCESS_TABLE_ENTRY_INFO>::iterator Iter = m_Ring3ProcessList.begin();
		Iter != m_Ring3ProcessList.end();
		Iter++)
	{
		//将逐一插入到控件中
		SeAddProcessInfoItem(*Iter);
	}
}


void CProcessManagerDialog::SeAddProcessInfoItem(PROCESS_TABLE_ENTRY_INFO ParameterData)
{
	if (ParameterData.ProcessIdentify == 0 && ParameterData.ParentProcessIdentify == 0)
	{
		//return;
	}
	CString ProcessIdentify, ParentProcessIdentify;


	//将十进制的数据转换成CString
	ProcessIdentify.Format(_T("%d"), ParameterData.ProcessIdentify);
	ParentProcessIdentify.Format(_T("%d"), ParameterData.ParentProcessIdentify);



	//插入
	int ItemCount = m_ProcessListCtrl.GetItemCount();  //获取排数




	int i = m_ProcessListCtrl.InsertItem(ItemCount, ParameterData.ImageName);
	m_ProcessListCtrl.SetItemText(i, 1, ProcessIdentify);
	m_ProcessListCtrl.SetItemText(i, 2, ParentProcessIdentify);
	m_ProcessListCtrl.SetItemText(i, 3, ParameterData.ImagePath);








	m_ProcessCount++;







}


